package com.example.allshengmedical.experimentnew.activity;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

import android.R.array;
import android.R.integer;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.LayoutManager;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.text.Selection;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.PopupWindow.OnDismissListener;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TimePicker;

import com.example.allshengmedical.R;
import com.example.allshengmedical.base.BaseActivity;
import com.example.allshengmedical.base.BaseApplication;
import com.example.allshengmedical.experimentnew.bean.MethodBean;
import com.example.allshengmedical.experimentnew.presenter.MethodsPresenter;
import com.example.allshengmedical.experimentnew.view.IMethodsView;
import com.example.allshengmedical.mainmenu.activity.MainMenuActivity;
import com.example.allshengmedical.util.ByAlert;
import com.example.allshengmedical.util.LogUtil;
import com.example.allshengmedical.util.MyHorizontalScrollView;
import com.example.allshengmedical.util.ScrollViewListener;
import com.example.allshengmedical.util.SharedPreferencesUtils;
import com.example.allshengmedical.util.SimpleLineChart;

//老板新建方法界面
public class MethodsActivity extends BaseActivity implements IMethodsView,
		OnClickListener, ScrollViewListener {

	private RecyclerView steptRv;
	private RecyclerViewAdapter recyclerViewAdapter;
	private ArrayList<MethodBean> activityMethodBeans;

	private MethodsPresenter methodsPresenter;

	private boolean menuboo;
	private PopupWindow menuPopupWindow, showMethodsPopupWindow;

	private SimpleLineChart mSimpleLineChart;
	private int pointnumber;
	private String[] xItem, yItem;

	private List<String> data_list = new ArrayList<String>();
	private ArrayAdapter<String> arr_adapter;

	// 保证线不交叉
	private HashSet<ArrayList<Integer>> range = new HashSet<ArrayList<Integer>>();
	// 保证每个终点不超过三个
	private HashMap<Integer, Integer> point3 = new HashMap<Integer, Integer>();

	// 下面的图表
	HashMap<Integer, Integer> pointMap = new HashMap();
	List<HashMap<String, Object>> pointMaps = new ArrayList<HashMap<String, Object>>();

	// 下面的横划
	MyHorizontalScrollView downScrollView;

	@Override
	protected int setcontent() {
		return R.layout.activity_new_methods;
	}

	@Override
	protected void initView() {

		downScrollView = BindView(R.id.downScrollView);
		downScrollView.setScrollViewListener(this);
		methodsPresenter = new MethodsPresenter(this);
		methodsPresenter.initAppHead();
		methodsPresenter.initBottomView();

		initRecyclerView();
		initSimpleLineChart();

	}

	@Override
	protected void initData() {

		point3.put(1, 0);
		point3.put(2, 0);
		point3.put(3, 0);
		point3.put(4, 0);
		point3.put(5, 0);
		point3.put(6, 0);
		point3.put(7, 0);
		point3.put(8, 0);
		point3.put(9, 0);
		point3.put(10, 0);
		point3.put(11, 0);
		point3.put(12, 0);
		point3.put(13, 0);
		point3.put(14, 0);
		point3.put(15, 0);
		point3.put(16, 0);
		point3.put(17, 0);
		point3.put(18, 0);
		point3.put(19, 0);
		point3.put(20, 0);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {

		default:
			break;
		}

	}

	@Override
	public void initAppHead() {
		setActionBar();
		setSystemTime();

	}

	@Override
	public void initBottomView() {
		setBottomView();

	}

	@Override
	public void AddAStep(View v) {
		chooseMethodPopupWindow(v);
	}

	@Override
	public void solubilityCurveEdit() {
		// TODO Auto-generated method stub

	}

	@Override
	public void steptEdit() {
		// TODO Auto-generated method stub

	}

	// 设置actionBar
	public void setActionBar() {
		Button leftfirstBtn, leftsecondBtn, leftThirdBtn, leftForthBtn, rightfirstBtn, rightsecondBtn, rightthirdBtn;
		final Button rightforthBtn;
		TextView title;

		leftfirstBtn = BindView(R.id.leftfirst_btn);
		leftsecondBtn = BindView(R.id.leftsecond_btn);
		rightfirstBtn = BindView(R.id.rightfirst_btn);
		rightsecondBtn = BindView(R.id.rightsecond_btn);
		rightthirdBtn = BindView(R.id.rightthird_btn);
		rightforthBtn = BindView(R.id.rightforth_btn);
		leftThirdBtn = BindView(R.id.leftThird_btn);
		leftForthBtn = BindView(R.id.leftForth_btn);

		title = BindView(R.id.title);

		leftfirstBtn.setVisibility(View.GONE);
		leftfirstBtn.setText(R.string.item_actionbar_menu);
		leftsecondBtn.setVisibility(View.VISIBLE);
		leftsecondBtn.setText(R.string.item_actionbar_home);
		rightfirstBtn.setVisibility(View.GONE);
		rightfirstBtn.setText(R.string.actionBar_new);
		rightsecondBtn.setVisibility(View.GONE);
		rightsecondBtn.setText(R.string.actionBar_saveAs);
		rightthirdBtn.setVisibility(View.GONE);
		rightthirdBtn.setText(R.string.actionBar_save);
		leftThirdBtn.setVisibility(View.VISIBLE);
		leftThirdBtn.setText("Load Methods");
		leftForthBtn.setVisibility(View.VISIBLE);
		leftForthBtn.setText("Save Methods");

		rightforthBtn.setVisibility(View.VISIBLE);

		title.setText("Methods");

		leftfirstBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (!menuboo) {
					showMenuPopupWindow(v);
					menuboo = !menuboo;
				} else {
					menuPopupWindow.dismiss();
					menuboo = !menuboo;
				}

			}

		});

		leftsecondBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(MethodsActivity.this,
						MainMenuActivity.class);
				startActivity(intent);
				finish();
			}
		});

		rightfirstBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("New");
				Intent intent = new Intent(MethodsActivity.this,
						FileManagerActivity.class);
				startActivity(intent);
			}
		});
		rightsecondBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("Save As");
				Intent intent = new Intent(MethodsActivity.this,
						FileManagerActivity.class);
				startActivity(intent);
			}
		});
		rightthirdBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				savePopupWindow(v);

			}

		});
		rightforthBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if (!rightforthBtn.isSelected()) {
					rightforthBtn.setSelected(!rightforthBtn.isSelected());
					showMethodsPopupWindow(v, rightforthBtn);
				} else {
					rightforthBtn.setSelected(!rightforthBtn.isSelected());
					showMethodsPopupWindow.dismiss();
//					ByAlert.alert("dissmisspopwindow");
				}

			}
		});

		leftThirdBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
//				ByAlert.alert("loadMethods");

			}
		});
		leftForthBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
//				ByAlert.alert("saveMethods");

			}
		});

	}

	// 获取当前时间的方法
	public void setSystemTime() {

		TextView date, fileName;
		date = BindView(R.id.date);
		fileName = BindView(R.id.file_name);

		// 获取系统时间
		SimpleDateFormat sdfDate = new SimpleDateFormat("MM dd,yyyy");
		date.setText(sdfDate.format(new Date()));

		// 文件路径置空
		fileName.setText("");

	}

	// 设置bottom布局
	public void setBottomView() {
		Button bottomLeftFistBtn, bottomCenterBtn, bottomRightBtn;

		bottomLeftFistBtn = BindView(R.id.bottomLeftFistBtn);
		bottomCenterBtn = BindView(R.id.bottomCenterBtn);
		bottomRightBtn = BindView(R.id.bottomRightBtn);

		bottomLeftFistBtn.setVisibility(View.VISIBLE);
//		bottomCenterBtn.setVisibility(View.VISIBLE);
		bottomRightBtn.setVisibility(View.VISIBLE);

		bottomLeftFistBtn.setText(R.string.bottomView_back);
		// TODO 这个button的文字不确定暂时用A代替
		bottomCenterBtn.setText("A"); // 不确定！！！！！！！
		bottomRightBtn.setText(R.string.bottomView_next);

		bottomLeftFistBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// ByAlert.alert("back");
				finish();

			}
		});

		bottomCenterBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("A");

			}
		});
		bottomRightBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(MethodsActivity.this,
						PreviewActivity.class);
				startActivity(intent);
			}
		});
	}

	// menu的弹出窗口
	private void showMenuPopupWindow(View v) {

		if (null == menuPopupWindow || !menuPopupWindow.isShowing()) {
			View contentView = LayoutInflater.from(this).inflate(
					R.layout.fragment_new_basicinformation_menu, null);

			menuPopupWindow = new PopupWindow(contentView,
					LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			menuPopupWindow.setBackgroundDrawable(new BitmapDrawable());
			menuPopupWindow.setTouchable(true);
			menuPopupWindow.setOutsideTouchable(true);
			menuPopupWindow.showAsDropDown(v, -40, -3);

			TextView basicInformationTv, layoutTv, methodTv, previewTv;
			basicInformationTv = (TextView) contentView
					.findViewById(R.id.basicInformationTv);
			layoutTv = (TextView) contentView.findViewById(R.id.layoutTv);
			methodTv = (TextView) contentView.findViewById(R.id.methodTv);
			previewTv = (TextView) contentView.findViewById(R.id.previewTv);

			basicInformationTv.setBackground(getResources().getDrawable(
					R.color.darkBlue));
			basicInformationTv.setTextColor(this.getResources().getColor(
					R.color.white));
			layoutTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					ByAlert.alert("跳转页面layout");

				}
			});
			methodTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					ByAlert.alert("跳转页面method");
				}
			});
			previewTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					ByAlert.alert("跳转页面preview");
				}
			});

		} else {
			menuPopupWindow.dismiss();
			menuboo = !menuboo;
		}

	}

	private void savePopupWindow(View v) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.dialog_baseinformation_save, null);

		Button confirmBtn, cancelBtn;

		confirmBtn = (Button) conteView.findViewById(R.id.confirm_btn);
		cancelBtn = (Button) conteView.findViewById(R.id.cancel_btn);

		final PopupWindow popupWindow = new PopupWindow(conteView,
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);

		popupWindow.setTouchable(true);

		popupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}

		});

		popupWindow.setBackgroundDrawable(new BitmapDrawable());
		popupWindow.setTouchable(true);
		popupWindow.setOutsideTouchable(true);
		popupWindow.showAtLocation(v, Gravity.CENTER, 0, 0);

		confirmBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// if (!whetherNull()) {
				// ByAlert.alert("保存失败");
				// popupWindow.dismiss();
				// return;
				// }
				// 创建文件

				popupWindow.dismiss();
			}

		});
		cancelBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				popupWindow.dismiss();
			}
		});

	}

	private void chooseMethodPopupWindow(View v) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.dialog_methods_step, null);

		TextView stepTv, solubilityCurveTv;
		stepTv = (TextView) conteView.findViewById(R.id.stepTv);
		solubilityCurveTv = (TextView) conteView
				.findViewById(R.id.solubilityCurveTv);

		final PopupWindow chooseMethodPopupWindow = new PopupWindow(conteView,
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);

		stepTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				chooseMethodPopupWindow.dismiss();
			}
		});

		solubilityCurveTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				chooseMethodPopupWindow.dismiss();
			}
		});

		chooseMethodPopupWindow.setTouchable(true);

		chooseMethodPopupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}

		});

		chooseMethodPopupWindow.setBackgroundDrawable(new BitmapDrawable());
		chooseMethodPopupWindow.setTouchable(true);
		chooseMethodPopupWindow.setOutsideTouchable(true);
		chooseMethodPopupWindow.showAtLocation(v, Gravity.CENTER, 0, -15);
	}

	private void initRecyclerView() {
		steptRv = BindView(R.id.steptRv);
		activityMethodBeans = new ArrayList<MethodBean>();

		// 数据

		if ("SYBR".equals(SharedPreferencesUtils.get(MethodsActivity.this,
				BaseApplication.BASEINFORMATION_REAGENT, ""))) {
			activityMethodBeans.add(new MethodBean("step", "95", "00:20:00",
					"", "", ""));
			activityMethodBeans.add(new MethodBean("step", "95", "00:01:00",
					"", "", ""));
			activityMethodBeans.add(new MethodBean("step", "60", "00:20:00",
					"2", "40", ""));
			activityMethodBeans.add(new MethodBean("step", "95", "00:15:00",
					"", "", ""));
			activityMethodBeans.add(new MethodBean("step", "60", "01:00:00",
					"", "", ""));
			activityMethodBeans.add(new MethodBean("solubilityCurve", "95",
					"00:15:00", "", "", "0.3"));

		} else if ("荧光标记探针".equals(SharedPreferencesUtils.get(
				MethodsActivity.this, BaseApplication.BASEINFORMATION_REAGENT,
				""))
				| "taqman".equals(SharedPreferencesUtils.get(
						MethodsActivity.this,
						BaseApplication.BASEINFORMATION_REAGENT, ""))) {
			activityMethodBeans.add(new MethodBean("step", "95", "00:20:00",
					"", "", ""));
			activityMethodBeans.add(new MethodBean("step", "95", "00:01:00",
					"", "", ""));
			activityMethodBeans.add(new MethodBean("step", "60", "00:20:00",
					"2", "40", ""));

		} else if ("其他".equals(SharedPreferencesUtils.get(MethodsActivity.this,
				BaseApplication.BASEINFORMATION_REAGENT, ""))
				| "Other".equals(SharedPreferencesUtils.get(
						MethodsActivity.this,
						BaseApplication.BASEINFORMATION_REAGENT, ""))) {
			// activityMethodBeans.add(new MethodBean("step", "50", "10:11:12",
			// "", "", ""));
			// activityMethodBeans.add(new MethodBean("solubilityCurve", "50",
			// "10:11:12", "", "", "70"));

		}

		LayoutManager layoutManager = new GridLayoutManager(this, 1);
		((GridLayoutManager) layoutManager)
				.setOrientation(OrientationHelper.HORIZONTAL);
		steptRv.setLayoutManager(layoutManager);
		recyclerViewAdapter = new RecyclerViewAdapter(activityMethodBeans);
		steptRv.setAdapter(recyclerViewAdapter);

		// 添加头布局（必须在设置完布局管理器再添加头布局和脚布局）
		// 添加脚布局
		View footView = View.inflate(this,
				R.layout.item_methods_step_create_new, null);

	}

	public class RecyclerViewAdapter extends
			RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {

		ArrayList<MethodBean> methodBeans = new ArrayList<MethodBean>();

		public RecyclerViewAdapter(ArrayList<MethodBean> methodBeans) {
			super();
			this.methodBeans = methodBeans;
		}

		class MyViewHolder extends ViewHolder {

			TextView temperatureTv, timeTv, deltaTTv, titleTv;
			LinearLayout line;
			LinearLayout orline;
			ImageView exitBtn;

			public MyViewHolder(View view) {
				super(view);
				temperatureTv = (TextView) view
						.findViewById(R.id.temperatureTv);
				timeTv = (TextView) view.findViewById(R.id.timeTv);
				deltaTTv = (TextView) view.findViewById(R.id.deltaTTv);
				line = (LinearLayout) view.findViewById(R.id.line);
				titleTv = (TextView) view.findViewById(R.id.titleTv);
				orline = (LinearLayout) view.findViewById(R.id.orline);
				exitBtn = (ImageView) view.findViewById(R.id.exitBtn);
			}
		}

		@Override
		public int getItemCount() {
			return methodBeans.size() >= 0 ? methodBeans.size() + 1 : 1;
		}

		@Override
		public int getItemViewType(int position) {

			if (position == methodBeans.size()) {
				return 0;
			}

			if ("step".equals(methodBeans.get(position).getSteptType())) {
				return 1;
			} else if ("solubilityCurve".equals(methodBeans.get(position)
					.getSteptType())) {
				return 2;
			}

			return 0;

		}

		@Override
		public void onBindViewHolder(MyViewHolder holder, final int position) {
			final int index = position + 1;
			if (getItemViewType(position) == 1) {
				holder.temperatureTv.setText(methodBeans.get(position)
						.getTemperature());
				holder.timeTv.setText(methodBeans.get(position).getTime());
				holder.titleTv.setText("Step" + index);

				holder.orline.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						upDate1PopupWindow(v, position);

					}

				});
				holder.exitBtn.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						if (index != activityMethodBeans.size()) {
							if ("solubilityCurve".equals(activityMethodBeans
									.get(position + 1).getSteptType())) {
								ByAlert.alert("下一个是溶解曲线不能删除！");
								return;
							}

						}

						if (position != 0) {
							if (!TextUtils.isEmpty(activityMethodBeans.get(
									position).getGoTo())) {
								ArrayList<Integer> linshilist = new ArrayList<Integer>();
								linshilist.add(Integer
										.parseInt(activityMethodBeans.get(
												position).getGoTo()));
								linshilist.add(position);
								range.remove(linshilist);
							}

						}

						// methodBeans.remove(position);
						activityMethodBeans.remove(position);
						notifyDataSetChanged();

						HashMap<Integer, Integer> pointMap1 = new HashMap();
						pointMap1.putAll(pointMap);
						// pointMap1.remove(position * 2);
						// pointMap1.remove(position * 2 + 1);
						pointMap.clear();
						int num = 0;
						for (int i = 0; i < pointMap1.size(); i++) {
							if (!(i == position * 2 || i == position * 2 + 1)) {
								pointMap.put(num, pointMap1.get(i));
								num++;
							}

						}
						UpdateView();

						pointnumber--;

					}
				});
			} else if (getItemViewType(position) == 2) {
				holder.temperatureTv.setText(methodBeans.get(position)
						.getTemperature());
				holder.timeTv.setText(methodBeans.get(position).getTime());
				holder.deltaTTv.setText(methodBeans.get(position).getDeltaT());
				holder.titleTv.setText("Step" + index);

				holder.orline.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						upDate2PopupWindow(v, position);

					}
				});
				holder.exitBtn.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						// methodBeans.remove(position);
						activityMethodBeans.remove(position);
						notifyDataSetChanged();
						// UpdateView();

						HashMap<Integer, Integer> pointMap1 = new HashMap();
						pointMap1.putAll(pointMap);
						// pointMap1.remove(position * 2);
						// pointMap1.remove(position * 2 + 1);
						pointMap.clear();
						int num = 0;
						for (int i = 0; i < pointMap1.size(); i++) {
							if (!(i == position * 2 || i == position * 2 + 1)) {
								pointMap.put(num, pointMap1.get(i));
								num++;
							}

						}
						UpdateView();
						pointnumber--;
					}
				});
			} else {
				holder.line.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						selectTypePopupWindow(v);

					}

				});
			}

		}

		@Override
		public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
			if (viewType == 1) {
				MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
						MethodsActivity.this).inflate(
						R.layout.item_methods_step_created, parent, false));
				return holder;
			} else if (viewType == 2) {
				MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
						MethodsActivity.this).inflate(
						R.layout.item_methods_solubility_curve_created, parent,
						false));
				return holder;
			} else {
				MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
						MethodsActivity.this).inflate(
						R.layout.item_methods_step_create_new, parent, false));
				return holder;
			}
		}
	}

	private void selectTypePopupWindow(final View view) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.dialog_methods_step, null);

		TextView stepTv, solubilityCurveTv;

		stepTv = (TextView) conteView.findViewById(R.id.stepTv);
		solubilityCurveTv = (TextView) conteView
				.findViewById(R.id.solubilityCurveTv);

		final PopupWindow selectTypePopupWindow = new PopupWindow(conteView,
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);

		selectTypePopupWindow.setTouchable(true);

		selectTypePopupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}

		});

		selectTypePopupWindow.setBackgroundDrawable(new BitmapDrawable());
		selectTypePopupWindow.setTouchable(true);
		selectTypePopupWindow.setOutsideTouchable(true);
		selectTypePopupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);

		stepTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				newStepPopupWindow(view);
				selectTypePopupWindow.dismiss();
			}

		});
		solubilityCurveTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				newSolubilityCurvePopupWindow(view);
				selectTypePopupWindow.dismiss();
			}

		});

	}

	private void newStepPopupWindow(final View view) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.item_methods_step_edit, null);

		final TextView temperatureTv;
		final TextView goToTv, repititionsTv;
		final TextView hourTv, minuteTv, secondTv;
		TextView confirmTv;

		temperatureTv = (TextView) conteView.findViewById(R.id.temperatureTv);
		goToTv = (TextView) conteView.findViewById(R.id.goToTv);
		repititionsTv = (TextView) conteView.findViewById(R.id.repititionsTv);

		hourTv = (TextView) conteView.findViewById(R.id.hourTv);
		minuteTv = (TextView) conteView.findViewById(R.id.minuteTv);
		secondTv = (TextView) conteView.findViewById(R.id.secondTv);

		confirmTv = (TextView) conteView.findViewById(R.id.confirmTv);

		final PopupWindow newStepPopupWindow = new PopupWindow(conteView,
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);

		temperatureTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, temperatureTv, true, null, null);

			}
		});
		goToTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, goToTv, false, null, null);

			}
		});
		repititionsTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, repititionsTv, false, null,
						null);

			}
		});
		hourTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("hour");
				numberKeyBoardPopupWindow(view, secondTv, false, minuteTv,
						secondTv);
				numberKeyBoardPopupWindow(view, minuteTv, false, minuteTv,
						secondTv);
				numberKeyBoardPopupWindow(view, hourTv, false, minuteTv,
						secondTv);

			}
		});
		minuteTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("minute");
				numberKeyBoardPopupWindow(view, secondTv, false, minuteTv,
						secondTv);
				numberKeyBoardPopupWindow(view, minuteTv, false, minuteTv,
						secondTv);

			}
		});
		secondTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, secondTv, false, minuteTv,
						secondTv);
			}
		});

		confirmTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if ("".equals(temperatureTv.getText().toString().trim())) {
					ByAlert.alert("温度不能为空");
					return;
				} else {
					int temperature = Integer.parseInt(temperatureTv.getText()
							.toString());
					if (temperature > 100) {
						ByAlert.alert("温度不能大于100摄氏度！");
						return;
					}
				}
				if ("".equals(hourTv.getText().toString().trim())) {
					ByAlert.alert("小时不能为空");
					return;
				}
				if ("".equals(minuteTv.getText().toString().trim())) {
					ByAlert.alert("分钟不能为空");
					return;
				} else {
					int minute = Integer
							.parseInt(minuteTv.getText().toString());
					if (minute >= 60) {
						ByAlert.alert("分钟数不能大于或等于60");
						return;
					}

				}
				if ("".equals(secondTv.getText().toString().trim())) {
					ByAlert.alert("秒不能为空");
					return;
				} else {
					int second = Integer.parseInt((String) secondTv.getText()
							.toString());
					if (second >= 60) {
						ByAlert.alert("秒数不能大于或等于60！");
						return;
					}

				}
				if (goToTv.getText().toString() != null
						&& !"".equals(goToTv.getText().toString())) {
					if (Integer.parseInt(goToTv.getText().toString()) >= activityMethodBeans
							.size() + 1) {
						ByAlert.alert("不能跳转本身和本身之后的步骤！");
						return;
					}
					if (point3.get(Integer
							.parseInt(goToTv.getText().toString())) > 3) {
						ByAlert.alert("同一个目标 只能添加三个");
						return;
					}
				}

				HashSet<Integer> arryArrayLists = new HashSet<Integer>();
				for (int i = 0; i < activityMethodBeans.size(); i++) {
					arryArrayLists.add(i + 1);
				}

				for (ArrayList<Integer> ranges : range) {

					if (ranges.get(0) != null & ranges.get(1) != null) {
						int minNum, maxNum;
						minNum = ranges.get(0);
						maxNum = ranges.get(1);
						HashSet<Integer> delSet = new HashSet<Integer>();
						for (int j = minNum + 1; j < maxNum; j++) {
							// arryArrayLists.remove(j);
							delSet.add(j);

						}
						arryArrayLists.removeAll(delSet);

						Boolean flag = false;
						for (int num : arryArrayLists) {

							if (goToTv.getText().toString() != null
									&& !"".equals(goToTv.getText().toString())) {
								if (Integer.parseInt(goToTv.getText()
										.toString()) == num) {
									flag = true;
								}
							} else {
								flag = true;
							}

						}
						if (!flag) {
							ByAlert.alert("不能交叉跳转");
							return;
						}

					} else {

					}

				}

				if (goToTv.getText().toString() != null
						&& !"".equals(goToTv.getText().toString())) {
					ArrayList<Integer> linShilist = new ArrayList<Integer>();
					linShilist.add(Integer
							.parseInt(goToTv.getText().toString()));
					linShilist.add(activityMethodBeans.size() + 1);

					point3.put(Integer.parseInt(goToTv.getText().toString()),
							point3.get(Integer.parseInt(goToTv.getText()
									.toString())) + 1);

					range.add(linShilist);
				}

				// ByAlert.alert("如果选中下一步，就必须要添加循环次数创建");

				activityMethodBeans.add(new MethodBean("step", temperatureTv
						.getText() + "℃", hourTv.getText() + ":"
						+ minuteTv.getText() + ":" + secondTv.getText(), goToTv
						.getText().toString(), repititionsTv.getText()
						.toString(), ""));

				pointMap.put(
						pointnumber * 2,
						10 - Integer.parseInt(activityMethodBeans
								.get(pointnumber).getTemperature()
								.replace("℃", "")) / 10);
				pointMap.put(
						pointnumber * 2 + 1,
						10 - Integer.parseInt(activityMethodBeans
								.get(pointnumber).getTemperature()
								.replace("℃", "")) / 10);
				pointnumber++;
				UpdateView();

				recyclerViewAdapter.notifyDataSetChanged();
				newStepPopupWindow.dismiss();
			}
		});

		newStepPopupWindow.setTouchable(true);

		newStepPopupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}

		});

		newStepPopupWindow.setBackgroundDrawable(new BitmapDrawable());
		newStepPopupWindow.setTouchable(true);
		newStepPopupWindow.setOutsideTouchable(true);
		newStepPopupWindow.showAtLocation(view, Gravity.CENTER, -200, 0);

	}

	private void newSolubilityCurvePopupWindow(final View view) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.item_methods_solubility_curve_edit, null);

		final TextView temperature1Tv, hour1Tv, minute1Tv, second1Tv;
		final TextView temperature2Tv, hour2Tv, minute2Tv, second2Tv;
		final TextView temperature3Tv, hour3Tv, minute3Tv, second3Tv;
		final TextView deltaTTv, cancelTv, confirmTv;

		temperature1Tv = (TextView) conteView.findViewById(R.id.temperature1Tv);
		temperature2Tv = (TextView) conteView.findViewById(R.id.temperature2Tv);
		temperature3Tv = (TextView) conteView.findViewById(R.id.temperature3Tv);
		hour1Tv = (TextView) conteView.findViewById(R.id.hour1Tv);
		minute1Tv = (TextView) conteView.findViewById(R.id.minute1Tv);
		second1Tv = (TextView) conteView.findViewById(R.id.second1Tv);
		hour2Tv = (TextView) conteView.findViewById(R.id.hour2Tv);
		minute2Tv = (TextView) conteView.findViewById(R.id.minute2Tv);
		second2Tv = (TextView) conteView.findViewById(R.id.second2Tv);
		hour3Tv = (TextView) conteView.findViewById(R.id.hour3Tv);
		minute3Tv = (TextView) conteView.findViewById(R.id.minute3Tv);
		second3Tv = (TextView) conteView.findViewById(R.id.second3Tv);

		deltaTTv = (TextView) conteView.findViewById(R.id.deltaTTv);

		cancelTv = (TextView) conteView.findViewById(R.id.cancelTv);
		confirmTv = (TextView) conteView.findViewById(R.id.confirmTv);

		final PopupWindow newSolubilityCurvePopupWindow = new PopupWindow(
				conteView, LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT, true);

		temperature1Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, temperature1Tv, true, null,
						null);

			}
		});
		hour1Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, hour1Tv, false, minute1Tv,
						second1Tv);

			}
		});
		hour2Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, hour2Tv, false, minute2Tv,
						second2Tv);

			}
		});
		hour3Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, hour3Tv, false, minute3Tv,
						second3Tv);

			}
		});
		minute1Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, minute1Tv, false, minute1Tv,
						second1Tv);

			}
		});
		minute2Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, minute2Tv, false, minute2Tv,
						second2Tv);

			}
		});
		minute3Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, minute3Tv, false, minute3Tv,
						second3Tv);

			}
		});
		second1Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, second1Tv, false, minute1Tv,
						second1Tv);

			}
		});
		second2Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, second2Tv, false, minute2Tv,
						second2Tv);

			}
		});
		second3Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, second3Tv, false, minute3Tv,
						second3Tv);

			}
		});
		temperature2Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, temperature2Tv, true, null,
						null);

			}
		});

		temperature3Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, temperature3Tv, true, null,
						null);

			}
		});

		deltaTTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, deltaTTv, true, null, null);

			}
		});
		cancelTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				newSolubilityCurvePopupWindow.dismiss();
			}
		});
		confirmTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if ("".equals(temperature1Tv.getText().toString().trim())
						| "".equals(temperature2Tv.getText().toString().trim())
						| "".equals(temperature3Tv.getText().toString().trim())) {
					ByAlert.alert("温度不能为空");
					return;
				} else {
					if (Integer.parseInt(temperature1Tv.getText().toString()
							.trim()) > 100) {
						ByAlert.alert("温度1不能大于100度");
						return;
					}
					if (Integer.parseInt(temperature2Tv.getText().toString()
							.trim()) > 100) {
						ByAlert.alert("温度2不能大于100度");
						return;
					}
					if (Integer.parseInt(temperature3Tv.getText().toString()
							.trim()) > 100) {
						ByAlert.alert("温度3不能大于100度");
						return;
					}
				}
				if ("".equals(minute1Tv.getText().toString().trim())
						| "".equals(minute2Tv.getText().toString().trim())
						| "".equals(minute3Tv.getText().toString().trim())) {
					ByAlert.alert("分钟不能为空");
				} else {
					if (Integer.parseInt(minute1Tv.getText().toString().trim()) >= 60) {
						ByAlert.alert("分钟1不能大于或等于60");
						return;
					}
					if (Integer.parseInt(minute2Tv.getText().toString().trim()) >= 60) {
						ByAlert.alert("分钟2不能大于或等于60");
						return;
					}
					if (Integer.parseInt(minute3Tv.getText().toString().trim()) >= 60) {
						ByAlert.alert("分钟3不能大于或等于60");
						return;
					}
				}
				if ("".equals(second1Tv.getText().toString().trim())
						| "".equals(second2Tv.getText().toString().trim())
						| "".equals(second3Tv.getText().toString().trim())) {
					ByAlert.alert("秒不能为空");
				} else {
					if (Integer.parseInt(second1Tv.getText().toString().trim()) >= 60) {
						ByAlert.alert("秒1不能大于或等于60");
						return;
					}
					if (Integer.parseInt(second2Tv.getText().toString().trim()) >= 60) {
						ByAlert.alert("秒2不能大于或等于60");
						return;
					}
					if (Integer.parseInt(second3Tv.getText().toString().trim()) >= 60) {
						ByAlert.alert("秒3不能大于或等于60");
						return;
					}
				}
				if ("".equals(deltaTTv.getText().toString().trim())) {
					ByAlert.alert("deltaT不能为空");
				} else {
					if (Integer.parseInt(deltaTTv.getText().toString().trim()) >= 100) {
						ByAlert.alert("deltaT不能大于或等于100");
						return;
					}
				}
				activityMethodBeans.add(new MethodBean("step", temperature1Tv
						.getText().toString() + "℃", hour1Tv.getText()
						.toString()
						+ ":"
						+ minute1Tv.getText().toString()
						+ ":" + second1Tv.getText().toString(), "", "", ""));
				activityMethodBeans.add(new MethodBean("step", temperature2Tv
						.getText().toString() + "℃", hour2Tv.getText()
						.toString()
						+ ":"
						+ minute2Tv.getText().toString()
						+ ":" + second2Tv.getText().toString(), "", "", ""));
				activityMethodBeans.add(new MethodBean("solubilityCurve",
						temperature3Tv.getText().toString() + "℃", hour3Tv
								.getText().toString()
								+ ":"
								+ minute3Tv.getText().toString()
								+ ":"
								+ second3Tv.getText().toString(), "", "", "+"
								+ deltaTTv.getText().toString() + "℃"));

				pointMap.put(
						pointnumber * 2,
						10 - Integer.parseInt(activityMethodBeans
								.get(pointnumber).getTemperature()
								.replace("℃", "")) / 10);
				pointMap.put(
						pointnumber * 2 + 1,
						10 - Integer.parseInt(activityMethodBeans
								.get(pointnumber).getTemperature()
								.replace("℃", "")) / 10);

				pointnumber++;

				pointMap.put(
						pointnumber * 2,
						10 - Integer.parseInt(activityMethodBeans
								.get(pointnumber).getTemperature()
								.replace("℃", "")) / 10);
				pointMap.put(
						pointnumber * 2 + 1,
						10 - Integer.parseInt(activityMethodBeans
								.get(pointnumber).getTemperature()
								.replace("℃", "")) / 10);

				pointnumber++;
				pointMap.put(
						pointnumber * 2,
						10 - Integer.parseInt(activityMethodBeans
								.get(pointnumber).getTemperature()
								.replace("℃", "")) / 10);
				pointMap.put(
						pointnumber * 2 + 1,
						10 - Integer.parseInt(activityMethodBeans
								.get(pointnumber).getTemperature()
								.replace("℃", "")) / 10);
				pointnumber++;

				UpdateView();

				recyclerViewAdapter.notifyDataSetChanged();
				newSolubilityCurvePopupWindow.dismiss();

			}
		});

		newSolubilityCurvePopupWindow.setTouchable(true);

		newSolubilityCurvePopupWindow
				.setTouchInterceptor(new OnTouchListener() {

					@Override
					public boolean onTouch(View v, MotionEvent event) {

						return false;
						// 这里如果返回true的话，touch事件将被拦截
						// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
					}

				});

		newSolubilityCurvePopupWindow
				.setBackgroundDrawable(new BitmapDrawable());
		newSolubilityCurvePopupWindow.setTouchable(true);
		newSolubilityCurvePopupWindow.setOutsideTouchable(true);
		newSolubilityCurvePopupWindow.showAtLocation(view, Gravity.CENTER,
				-200, 0);

	}

	// 配置数字键盘的popupwindow
	private void numberKeyBoardPopupWindow(View v, final TextView textv,
			Boolean type, final TextView minuteTv, final TextView secondTv) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.item_numkeyboard, null);

		final EditText showTv;
		TextView num0Tv, num1Tv, num2Tv, num3Tv, num4Tv, num5Tv, num6Tv, num7Tv, num8Tv, num9Tv, num10Tv, cancelTv, confirmTv;
		showTv = (EditText) conteView.findViewById(R.id.showTv);
		num0Tv = (TextView) conteView.findViewById(R.id.num0Tv);
		num1Tv = (TextView) conteView.findViewById(R.id.num1Tv);
		num2Tv = (TextView) conteView.findViewById(R.id.num2Tv);
		num3Tv = (TextView) conteView.findViewById(R.id.num3Tv);
		num4Tv = (TextView) conteView.findViewById(R.id.num4Tv);
		num5Tv = (TextView) conteView.findViewById(R.id.num5Tv);
		num6Tv = (TextView) conteView.findViewById(R.id.num6Tv);
		num7Tv = (TextView) conteView.findViewById(R.id.num7Tv);
		num8Tv = (TextView) conteView.findViewById(R.id.num8Tv);
		num9Tv = (TextView) conteView.findViewById(R.id.num9Tv);
		confirmTv = (TextView) conteView.findViewById(R.id.confirmTv);
		cancelTv = (TextView) conteView.findViewById(R.id.cancelTv);

		final PopupWindow numberKeyBoardPopupWindow = new PopupWindow(
				conteView, LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT, true);

		confirmTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if (showTv.getText().length() == 0) {
					if (R.id.hourTv == textv.getId()) {
						textv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
						minuteTv.setBackground(getResources().getDrawable(
								R.drawable.shape_darkblueblackframe));
					} else if (R.id.minuteTv == textv.getId()) {

						minuteTv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
						secondTv.setBackground(getResources().getDrawable(
								R.drawable.shape_darkblueblackframe));

					} else if (R.id.secondTv == textv.getId()) {

						secondTv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
					}
					numberKeyBoardPopupWindow.dismiss();
					return;
				}
				if (R.id.hourTv == textv.getId()
						| R.id.minuteTv == textv.getId()
						| R.id.secondTv == textv.getId()) {

					if (R.id.hourTv == textv.getId()) {
						textv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
						minuteTv.setBackground(getResources().getDrawable(
								R.drawable.shape_darkblueblackframe));
					} else if (R.id.minuteTv == textv.getId()) {
						int result = Integer.parseInt(showTv.getText()
								.toString());
						if (result >= 60) {
							showTv.setText("");
							return;
						}
						minuteTv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
						secondTv.setBackground(getResources().getDrawable(
								R.drawable.shape_darkblueblackframe));

						showTv.setText(result + "");
					} else if (R.id.secondTv == textv.getId()) {

						int result = Integer.parseInt(showTv.getText()
								.toString());
						if (result >= 60) {
							showTv.setText("");
							return;
						}
						secondTv.setBackground(getResources().getDrawable(
								R.drawable.shape_blackframe));
					}

					DecimalFormat df = new DecimalFormat("00");
					textv.setText(df.format(Integer.parseInt(showTv.getText()
							.toString())) + "");

					numberKeyBoardPopupWindow.dismiss();
				} else {
					textv.setText(showTv.getText());
					numberKeyBoardPopupWindow.dismiss();
				}

			}
		});

		if (type) {
			cancelTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					showTv.setText(showTv.getText().append("."));
					Selection.setSelection(showTv.getText(), showTv.getText()
							.length());

				}
			});
		} else {
			numberKeyBoardPopupWindow.dismiss();
		}

		num0Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("0"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});
		num1Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("1"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		num2Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("2"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});
		num3Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("3"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		num3Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("3"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});
		num4Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("4"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});
		num5Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("5"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		num6Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("6"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		num7Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("7"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});
		num8Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("8"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		num9Tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showTv.setText(showTv.getText().append("9"));
				Selection.setSelection(showTv.getText(), showTv.getText()
						.length());

			}
		});

		numberKeyBoardPopupWindow.setTouchable(true);

		numberKeyBoardPopupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				
//				if (R.id.hourTv == textv.getId()) {
//					minuteTv.setBackground(getResources().getDrawable(
//							R.drawable.shape_blackframe));
//					textv.setBackground(getResources().getDrawable(
//							R.drawable.shape_darkblueblackframe));
//				} else if (R.id.minuteTv == textv.getId()) {
//
//					minuteTv.setBackground(getResources().getDrawable(
//							R.drawable.shape_blackframe));
//					secondTv.setBackground(getResources().getDrawable(
//							R.drawable.shape_darkblueblackframe));
//
//				} else if (R.id.secondTv == textv.getId()) {
//
//					secondTv.setBackground(getResources().getDrawable(
//							R.drawable.shape_blackframe));
//				}
				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}

		});

		numberKeyBoardPopupWindow.setBackgroundDrawable(new BitmapDrawable());
		numberKeyBoardPopupWindow.setTouchable(true);
		numberKeyBoardPopupWindow.setOutsideTouchable(true);
		numberKeyBoardPopupWindow.showAtLocation(v, Gravity.CENTER, 200, 75);

	}

	private void upDate1PopupWindow(final View view, final int position) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.item_methods_step_edit, null);

		final TextView temperatureTv, stepName;
		final TextView goToTv, repititionsTv;
		final TextView hourTv, minuteTv, secondTv;
		TextView confirmTv, repititiontextTv;
		TextView gototextTv;

		temperatureTv = (TextView) conteView.findViewById(R.id.temperatureTv);
		goToTv = (TextView) conteView.findViewById(R.id.goToTv);
		repititionsTv = (TextView) conteView.findViewById(R.id.repititionsTv);
		gototextTv = (TextView) conteView.findViewById(R.id.gototextTv);
		repititiontextTv = (TextView) conteView
				.findViewById(R.id.repititiontextTv);

		hourTv = (TextView) conteView.findViewById(R.id.hourTv);
		minuteTv = (TextView) conteView.findViewById(R.id.minuteTv);
		secondTv = (TextView) conteView.findViewById(R.id.secondTv);

		confirmTv = (TextView) conteView.findViewById(R.id.confirmTv);
		stepName = (TextView) conteView.findViewById(R.id.stepName);

		final PopupWindow upDate1PopupWindow = new PopupWindow(conteView,
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
		temperatureTv.setText(activityMethodBeans.get(position)
				.getTemperature().replace("℃", ""));
		goToTv.setText(activityMethodBeans.get(position).getGoTo());
		repititionsTv.setText(activityMethodBeans.get(position)
				.getRepititions());
		String time = activityMethodBeans.get(position).getTime();
		hourTv.setText(time.substring(0, time.indexOf(":")));
		int firstSymbol;
		firstSymbol = time.indexOf(":");
		minuteTv.setText(time.substring(firstSymbol + 1,
				time.indexOf(":", firstSymbol + 1)));
		int secondSymbol;
		secondSymbol = time.indexOf(":", firstSymbol + 1);
		secondTv.setText(time.substring(time.indexOf(":", secondSymbol) + 1));
		int index = position + 1;
		stepName.setText("step" + index);

		temperatureTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, temperatureTv, true, null, null);

			}
		});

		if (position == 0) {
			goToTv.setVisibility(View.INVISIBLE);
			gototextTv.setVisibility(View.INVISIBLE);
			repititionsTv.setVisibility(View.INVISIBLE);
			repititiontextTv.setVisibility(View.INVISIBLE);

		}
		goToTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, goToTv, false, null, null);

			}
		});
		repititionsTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, repititionsTv, false, null,
						null);

			}
		});
		hourTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("hour");
				hourTv.setBackground(getResources().getDrawable(
						R.drawable.shape_darkblueblackframe));
				numberKeyBoardPopupWindow(view, secondTv, false, minuteTv,
						secondTv);

				numberKeyBoardPopupWindow(view, minuteTv, false, minuteTv,
						secondTv);
				// minuteTv.setBackground(getResources().getDrawable(R.drawable.shape_blackframe));
				// secondTv.setBackground(getResources().getDrawable(R.drawable.shape_darkblueblackframe));
				numberKeyBoardPopupWindow(view, hourTv, false, minuteTv,
						secondTv);
				// secondTv.setBackground(getResources().getDrawable(R.drawable.shape_blackframe));

			}
		});
		minuteTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("minute");
				minuteTv.setBackground(getResources().getDrawable(
						R.drawable.shape_darkblueblackframe));
				numberKeyBoardPopupWindow(view, secondTv, false, minuteTv,
						secondTv);
				numberKeyBoardPopupWindow(view, minuteTv, false, minuteTv,
						secondTv);

			}
		});
		secondTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				secondTv.setBackground(getResources().getDrawable(
						R.drawable.shape_darkblueblackframe));
				numberKeyBoardPopupWindow(view, secondTv, false, minuteTv,
						secondTv);
			}
		});

		confirmTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if ("".equals(temperatureTv.getText().toString().trim())) {
					ByAlert.alert("温度不能为空");
					return;
				} else {
					int temperature = Integer.parseInt(temperatureTv.getText()
							.toString());
					if (temperature > 100) {
						ByAlert.alert("温度不能大于100摄氏度！");
						return;
					}
				}
				if ("".equals(hourTv.getText().toString().trim())) {
					ByAlert.alert("小时不能为空");
					return;
				}
				if ("".equals(minuteTv.getText().toString().trim())) {
					ByAlert.alert("分钟不能为空");
					return;
				} else {
					int minute = Integer
							.parseInt(minuteTv.getText().toString());
					if (minute >= 60) {
						ByAlert.alert("分钟数不能大于或等于60");
						return;
					}

				}
				if ("".equals(secondTv.getText().toString().trim())) {
					ByAlert.alert("秒不能为空");
					return;
				} else {
					int second = Integer.parseInt((String) secondTv.getText()
							.toString());
					if (second >= 60) {
						ByAlert.alert("秒数不能大于或等于60");
						return;
					}

				}
				if (!"".equals(goToTv.getText().toString())
						|| goToTv.getText().toString() != null) {

					if (position != 0) {

						if (!TextUtils.isEmpty(goToTv.getText().toString())) {
							if (Integer.parseInt(goToTv.getText().toString()) >= activityMethodBeans
									.size() + 1) {
								ByAlert.alert("不能跳转本身和本身之后的步骤！");
								return;
							}
						}

					}

				}

				if (position != 0) {

					if (!TextUtils.isEmpty(activityMethodBeans.get(position)
							.getGoTo())) {
						ArrayList<Integer> linshilist = new ArrayList<Integer>();
						linshilist.add(Integer.parseInt(activityMethodBeans
								.get(position).getGoTo()));
						linshilist.add(position);
						range.remove(linshilist);
					}

				}

				HashSet<Integer> arryArrayLists = new HashSet<Integer>();
				for (int i = 0; i < activityMethodBeans.size(); i++) {
					arryArrayLists.add(i + 1);
				}

				for (ArrayList<Integer> ranges : range) {

					if (ranges.get(0) != null & ranges.get(1) != null) {
						int minNum, maxNum;
						minNum = ranges.get(0);
						maxNum = ranges.get(1);
						HashSet<Integer> delSet = new HashSet<Integer>();
						for (int j = minNum + 1; j < maxNum; j++) {
							// arryArrayLists.remove(j);
							delSet.add(j);

						}
						arryArrayLists.removeAll(delSet);

						Boolean flag = false;
						for (int num : arryArrayLists) {
							if (!TextUtils.isEmpty(goToTv.getText().toString())) {
								if (Integer.parseInt(goToTv.getText()
										.toString()) == num) {
									flag = true;
								}
							} else {
								flag = true;
							}

						}
						if (!flag) {
							ByAlert.alert("不能交叉跳转");
							ByAlert.alert("若无法达到需要的跳转，请删除步骤后重新设置！");
							return;
						}

					} else {

					}

				}

				if (position != 0) {
					if (!TextUtils.isEmpty(goToTv.getText().toString())) {
						ArrayList<Integer> linShilist = new ArrayList<Integer>();
						linShilist.add(Integer.parseInt(goToTv.getText()
								.toString()));
						linShilist.add(activityMethodBeans.size() + 1);

						range.add(linShilist);
					}

				}

				ByAlert.alert("如果选中下一步，就必须要添加循环次数创建");
				activityMethodBeans.get(position).setTemperature(
						temperatureTv.getText() + "℃");
				activityMethodBeans.get(position).setTime(
						hourTv.getText() + ":" + minuteTv.getText() + ":"
								+ secondTv.getText());
				activityMethodBeans.get(position).setGoTo(
						goToTv.getText().toString());
				activityMethodBeans.get(position).setRepititions(
						repititionsTv.getText().toString());

				pointMap.remove(position * 2);
				pointMap.remove(position * 2 + 1);

				pointMap.put(
						position * 2,
						10 - Integer.parseInt(activityMethodBeans.get(position)
								.getTemperature().replace("℃", "")) / 10);
				pointMap.put(
						position * 2 + 1,
						10 - Integer.parseInt(activityMethodBeans.get(position)
								.getTemperature().replace("℃", "")) / 10);

				UpdateView();

				recyclerViewAdapter.notifyDataSetChanged();
				upDate1PopupWindow.dismiss();
			}
		});

		upDate1PopupWindow.setTouchable(true);

		upDate1PopupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}

		});

		upDate1PopupWindow.setBackgroundDrawable(new BitmapDrawable());
		upDate1PopupWindow.setTouchable(true);
		upDate1PopupWindow.setOutsideTouchable(true);
		upDate1PopupWindow.showAtLocation(view, Gravity.CENTER, -200, 90);

	}

	private void upDate2PopupWindow(final View view, final int position) {
		View conteView = LayoutInflater.from(this).inflate(
				R.layout.item_methods_solubility_curve_newcreate, null);

		Button addBtn, minusBtn;
		final TextView temperatureTv, stepName;
		final TextView deltaTTv;
		final TextView hourTv, minuteTv, secondTv;
		TextView confirmTv;

		addBtn = (Button) conteView.findViewById(R.id.addBtn);
		minusBtn = (Button) conteView.findViewById(R.id.minusBtn);
		temperatureTv = (TextView) conteView.findViewById(R.id.temperatureTv);

		hourTv = (TextView) conteView.findViewById(R.id.hourTv);
		minuteTv = (TextView) conteView.findViewById(R.id.minuteTv);
		secondTv = (TextView) conteView.findViewById(R.id.secondTv);

		deltaTTv = (TextView) conteView.findViewById(R.id.deltaTTv);

		confirmTv = (TextView) conteView.findViewById(R.id.confirmTv);
		stepName = (TextView) conteView.findViewById(R.id.stepName);

		final PopupWindow upDate2PopupWindow = new PopupWindow(conteView,
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);

		int index = position + 1;
		stepName.setText("step" + index);
		temperatureTv.setText(activityMethodBeans.get(position)
				.getTemperature());

		String time = activityMethodBeans.get(position).getTime();
		hourTv.setText(time.substring(0, time.indexOf(":")));
		int firstSymbol;
		firstSymbol = time.indexOf(":");
		minuteTv.setText(time.substring(firstSymbol + 1,
				time.indexOf(":", firstSymbol + 1)));
		int secondSymbol;
		secondSymbol = time.indexOf(":", firstSymbol + 1);
		secondTv.setText(time.substring(time.indexOf(":", secondSymbol) + 1));
		deltaTTv.setText(activityMethodBeans.get(position).getDeltaT()
				.replace("℃", "").replace("+", ""));

		final DecimalFormat df = new DecimalFormat("###0.0");
		addBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String result = df.format((Double.parseDouble(deltaTTv
						.getText().toString()) + (Double) 0.1));
				deltaTTv.setText(result);

			}
		});
		minusBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String result = df.format((Double.parseDouble(deltaTTv
						.getText().toString()) - (Double) 0.1));
				deltaTTv.setText(result);
			}
		});

		temperatureTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, temperatureTv, true, null, null);

			}
		});

		hourTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("hour");
				numberKeyBoardPopupWindow(view, hourTv, false, minuteTv,
						secondTv);

			}
		});
		minuteTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("minute");
				numberKeyBoardPopupWindow(view, minuteTv, false, minuteTv,
						secondTv);

			}
		});
		secondTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				numberKeyBoardPopupWindow(view, secondTv, false, minuteTv,
						secondTv);
			}
		});

		confirmTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if ("".equals(temperatureTv.getText().toString().trim())) {
					ByAlert.alert("温度不能为空");
					return;
				} else {
					int temperature = Integer.parseInt(temperatureTv.getText()
							.toString());
					if (temperature > 100) {
						ByAlert.alert("温度不能大于100摄氏度！");
						return;
					}
				}
				if ("".equals(hourTv.getText().toString().trim())) {
					ByAlert.alert("小时不能为空");
					return;
				}
				if ("".equals(minuteTv.getText().toString().trim())) {
					ByAlert.alert("分钟不能为空");
					return;
				} else {
					int minute = Integer
							.parseInt(minuteTv.getText().toString());
					if (minute >= 60) {
						ByAlert.alert("分钟数不能大于或等于60");
						return;
					}

				}
				if ("".equals(secondTv.getText().toString().trim())) {
					ByAlert.alert("秒不能为空");
					return;
				} else {
					int second = Integer.parseInt((String) secondTv.getText()
							.toString());
					if (second >= 60) {
						ByAlert.alert("秒数不能大于或等于60");
						return;
					}

				}

				ByAlert.alert("如果选中下一步，就必须要添加循环次数创建");
				activityMethodBeans.get(position).setTemperature(
						temperatureTv.getText() + "℃");
				activityMethodBeans.get(position).setTime(
						hourTv.getText() + ":" + minuteTv.getText() + ":"
								+ secondTv.getText());
				activityMethodBeans.get(position).setDeltaT(
						"+" + deltaTTv.getText().toString() + "℃");

				pointMap.remove(position * 2);
				pointMap.remove(position * 2 + 1);

				pointMap.put(
						position * 2,
						10 - Integer.parseInt(activityMethodBeans.get(position)
								.getTemperature().replace("℃", "")) / 10);
				pointMap.put(
						position * 2 + 1,
						10 - Integer.parseInt(activityMethodBeans.get(position)
								.getTemperature().replace("℃", "")) / 10);
				recyclerViewAdapter.notifyDataSetChanged();
				upDate2PopupWindow.dismiss();
				UpdateView();
			}
		});

		upDate2PopupWindow.setTouchable(true);

		upDate2PopupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}

		});

		upDate2PopupWindow.setBackgroundDrawable(new BitmapDrawable());
		upDate2PopupWindow.setTouchable(true);
		upDate2PopupWindow.setOutsideTouchable(true);
		upDate2PopupWindow.showAtLocation(view, Gravity.CENTER, -200, 85);

	}

	// 初始化折线图
	private void initSimpleLineChart() {
		mSimpleLineChart = (SimpleLineChart) findViewById(R.id.simpleLineChart);

		// for (int i = 0; i < activityMethodBeans.size(); i++) {
		// pointMaps.get(i).put("temperature",
		// activityMethodBeans.get(i).getTemperature());
		// pointMaps.get(i).put("time", activityMethodBeans.get(i).getTime());
		// pointMaps.get(i).put("deltaT",
		// activityMethodBeans.get(i).getDeltaT());
		// pointMaps.get(i).put("gotTo", activityMethodBeans.get(i).getGoTo());
		// pointMaps.get(i).put("repititions",
		// activityMethodBeans.get(i).getRepititions());
		//
		// }

		if ("SYBR".equals(SharedPreferencesUtils.get(MethodsActivity.this,
				BaseApplication.BASEINFORMATION_REAGENT, ""))) {

			String[] xItem = { "Step1", "", "Step2", "", "Step3", "", "Step4",
					"", "Step5", "", "Step6", "" };
			String[] yItem = { "", "", "", "", "", "", "", "", "", "", "" };
			if (mSimpleLineChart == null)
				Log.e("wing", "null!!!!");
			mSimpleLineChart.setXItem(xItem);
			mSimpleLineChart.setYItem(yItem);

		} else if ("荧光标记探针".equals(SharedPreferencesUtils.get(
				MethodsActivity.this, BaseApplication.BASEINFORMATION_REAGENT,
				""))
				| "taqman".equals(SharedPreferencesUtils.get(
						MethodsActivity.this,
						BaseApplication.BASEINFORMATION_REAGENT, ""))) {
			String[] xItem = { "Step1", "", "Step2", "", "Step3", "" };
			String[] yItem = { "", "", "", "", "", "", "", "", "", "", "" };
			if (mSimpleLineChart == null)
				Log.e("wing", "null!!!!");
			mSimpleLineChart.setXItem(xItem);
			mSimpleLineChart.setYItem(yItem);

		} else if ("其他".equals(SharedPreferencesUtils.get(MethodsActivity.this,
				BaseApplication.BASEINFORMATION_REAGENT, ""))
				| "Other".equals(SharedPreferencesUtils.get(
						MethodsActivity.this,
						BaseApplication.BASEINFORMATION_REAGENT, ""))) {
			String[] xItem = { "" };
			String[] yItem = { "", "", "", "", "", "", "", "", "", "", "" };
			if (mSimpleLineChart == null)
				Log.e("wing", "null!!!!");
			mSimpleLineChart.setXItem(xItem);
			mSimpleLineChart.setYItem(yItem);
		}

		// for (int i = 0; i < xItem.length; i++) {
		// pointMap.put(i, (int) (Math.random() * 5));
		// }

		for (int i = 0; i < 40; i++) {
			HashMap<String, Object> itemHashMap = new HashMap<String, Object>();
			// x
			itemHashMap.put("x", i);
			// y
			itemHashMap.put("y", "");
			// 温度
			itemHashMap.put("temperature", "");
			// 时间
			itemHashMap.put("time", "");
			// DeltaT
			itemHashMap.put("deltaT", "");
			// gotTo
			itemHashMap.put("goTo", "");
			// Repititions
			itemHashMap.put("repititions", "");
			pointMaps.add(itemHashMap);

		}
		for (int i = 0; i < activityMethodBeans.size(); i++) {
			pointMaps.get(i).put("temperature",
					activityMethodBeans.get(i).getTemperature());
			pointMaps.get(i).put("time", activityMethodBeans.get(i).getTime());
			pointMaps.get(i).put("deltaT",
					activityMethodBeans.get(i).getDeltaT());
			pointMaps.get(i).put("gotTo", activityMethodBeans.get(i).getGoTo());
			pointMaps.get(i).put("repititions",
					activityMethodBeans.get(i).getRepititions());

		}

		if ("SYBR".equals(SharedPreferencesUtils.get(MethodsActivity.this,
				BaseApplication.BASEINFORMATION_REAGENT, ""))) {

			pointMap.put(0, 10 - 9);
			pointMap.put(1, 10 - 9);
			pointMap.put(2, 10 - 9);
			pointMap.put(3, 10 - 9);
			pointMap.put(4, 10 - 6);
			pointMap.put(5, 10 - 6);
			pointMap.put(6, 10 - 9);
			pointMap.put(7, 10 - 9);
			pointMap.put(8, 10 - 6);
			pointMap.put(9, 10 - 6);
			pointMap.put(10, 10 - 9);
			pointMap.put(11, 10 - 9);
			pointnumber = 6;

		} else if ("荧光标记探针".equals(SharedPreferencesUtils.get(
				MethodsActivity.this, BaseApplication.BASEINFORMATION_REAGENT,
				""))
				| "taqman".equals(SharedPreferencesUtils.get(
						MethodsActivity.this,
						BaseApplication.BASEINFORMATION_REAGENT, ""))) {
			pointMap.put(0, 10 - 9);
			pointMap.put(1, 10 - 9);
			pointMap.put(2, 10 - 9);
			pointMap.put(3, 10 - 9);
			pointMap.put(4, 10 - 6);
			pointMap.put(5, 10 - 6);
			pointnumber = 3;

		} else if ("其他".equals(SharedPreferencesUtils.get(MethodsActivity.this,
				BaseApplication.BASEINFORMATION_REAGENT, ""))
				| "Other".equals(SharedPreferencesUtils.get(
						MethodsActivity.this,
						BaseApplication.BASEINFORMATION_REAGENT, ""))) {

		}

		// pointMap.put(0, 10 - 3);
		// pointMap.put(1, 10 - 3);
		// pointMap.put(2, 10 - 1);
		// pointMap.put(3, 10 - 1);
		// pointMap.put(4, 10 - 0);
		// pointMap.put(5, 10 - 0);
		// pointMap.put(6, 10 - 0);
		// pointMap.put(7, 10 - 0);
		// pointMap.put(8, 10 - 0);
		// pointMap.put(9, 10 - 0);
		// pointMap.put(10, 10 - 0);
		// pointMap.put(11, 10 - 0);
		// pointMap.put(12, 10 - 0);
		// pointMap.put(13, 10 - 0);
		// pointMap.put(14, 10 - 0);
		// pointMap.put(15, 10 - 0);
		// pointMap.put(16, 10 - 0);
		// pointMap.put(17, 10 - 0);
		// pointMap.put(18, 10 - 0);
		// pointMap.put(19, 10 - 0);
		// pointMap.put(20, 10 - 0);
		// pointMap.put(21, 10 - 0);
		// pointMap.put(22, 10 - 0);
		// pointMap.put(23, 10 - 0);
		// pointMap.put(24, 10 - 0);
		// pointMap.put(25, 10 - 0);
		// pointMap.put(26, 10 - 0);
		// pointMap.put(27, 10 - 0);
		// pointMap.put(28, 10 - 0);
		// pointMap.put(29, 10 - 0);
		// pointMap.put(30, 10 - 0);
		// pointMap.put(31, 10 - 0);
		// pointMap.put(32, 10 - 0);
		// pointMap.put(33, 10 - 0);
		// pointMap.put(34, 10 - 0);
		// pointMap.put(35, 10 - 0);
		// pointMap.put(36, 10 - 0);
		// pointMap.put(37, 10 - 0);
		// pointMap.put(38, 10 - 0);
		// pointMap.put(39, 10 - 0);

		mSimpleLineChart.setData(pointMap);
		mSimpleLineChart.setData2(pointMaps);
	}

	private void UpdateView() {

		switch (pointMap.size()) {
		case 0:
			xItem = new String[] { "" };
			break;
		case 1:
			xItem = new String[] { "Step1" };
			break;
		case 2:
			xItem = new String[] { "Step1", "", };
			break;
		case 3:
			xItem = new String[] { "Step1", "", "Step2" };
			break;
		case 4:
			xItem = new String[] { "Step1", "", "Step2", "" };
			break;
		case 5:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3" };
			break;
		case 6:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "" };
			break;

		case 7:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4" };
			break;
		case 8:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "" };
			break;
		case 9:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5" };
			break;
		case 10:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "" };
			break;
		case 11:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6" };
			break;
		case 12:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "" };
			break;
		case 13:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7" };
			break;
		case 14:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "" };
			break;
		case 15:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "", "Step8" };
			break;
		case 16:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "" };
			break;
		case 17:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9" };
			break;
		case 18:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "" };
			break;
		case 19:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10" };
			break;
		case 20:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "" };
			break;
		case 21:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11" };
			break;
		case 22:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "" };
			break;
		case 23:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12" };
			break;
		case 24:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "" };
			break;
		case 25:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13" };
			break;
		case 26:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "" };
			break;
		case 27:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14" };
			break;
		case 28:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "" };
			break;
		case 29:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15" };
			break;
		case 30:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "" };
			break;
		case 31:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16" };
			break;
		case 32:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "" };
			break;
		case 33:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17" };
			break;
		case 34:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "" };
			break;
		case 35:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18" };
			break;
		case 36:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "" };
			break;
		case 37:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "", "Step19" };
			break;
		case 38:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "", "Step19", "" };
			break;
		case 39:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "", "Step19", "",
					"Step20" };
			break;
		case 40:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "", "Step19", "",
					"Step20", "" };

			break;

		default:
			break;
		}
		mSimpleLineChart.setXItem(xItem);

		for (int i = 0; i < activityMethodBeans.size(); i++) {
			pointMaps.get(i).put("temperature",
					activityMethodBeans.get(i).getTemperature());
			pointMaps.get(i).put("time", activityMethodBeans.get(i).getTime());
			pointMaps.get(i).put("deltaT",
					activityMethodBeans.get(i).getDeltaT());
			pointMaps.get(i).put("gotTo", activityMethodBeans.get(i).getGoTo());
			pointMaps.get(i).put("repititions",
					activityMethodBeans.get(i).getRepititions());

		}

		mSimpleLineChart.setData(pointMap);
		mSimpleLineChart.setData2(pointMaps);
	}

	// menu的弹出窗口
	private void showMethodsPopupWindow(final View view, final Button btn) {

		if (null == showMethodsPopupWindow
				|| !showMethodsPopupWindow.isShowing()) {
			View contentView = LayoutInflater.from(MethodsActivity.this)
					.inflate(R.layout.fragment_methods_menu, null);

			showMethodsPopupWindow = new PopupWindow(contentView,
					LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			showMethodsPopupWindow.setBackgroundDrawable(new BitmapDrawable());
			showMethodsPopupWindow.setTouchable(true);
			showMethodsPopupWindow.setOutsideTouchable(true);
			showMethodsPopupWindow.showAsDropDown(view, -40, -3);

			final TextView temperatureTv;
			final TextView volumeTv;
			final TextView stepSpinner;
			TextView confirmTv;
			temperatureTv = (TextView) contentView
					.findViewById(R.id.temperatureTv);
			volumeTv = (TextView) contentView.findViewById(R.id.volumeTv);
			stepSpinner = (TextView) contentView.findViewById(R.id.stepSpinner);
			confirmTv = (TextView) contentView.findViewById(R.id.confirmTv);

			temperatureTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					numberKeyBoardPopupWindow(view, temperatureTv, false, null,
							null);
				}
			});
			volumeTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					numberKeyBoardPopupWindow(view, volumeTv, false, null, null);
				}
			});
			stepSpinner.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					numberKeyBoardPopupWindow(view, stepSpinner, false, null,
							null);
				}
			});
			confirmTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					if (TextUtils.isEmpty(temperatureTv.getText().toString())
							& TextUtils.isEmpty(volumeTv.getText().toString())
							& TextUtils.isEmpty(stepSpinner.getText()
									.toString())) {

						ByAlert.alert("以上信息不能为空");
						return;

					} else {
						if (Integer.parseInt(stepSpinner.getText().toString()) > activityMethodBeans
								.size()) {
							ByAlert.alert("读取数据的步骤输入有误");
							return;
						}
					}
				}
			});

		} else {
			btn.setSelected(!btn.isSelected());
			showMethodsPopupWindow.dismiss();
		}

	}

	@Override
	public void onScrollChanged(MyHorizontalScrollView scrollView, int x,
			int y, int oldx, int oldy) {

		if (scrollView == downScrollView) {

			steptRv.smoothScrollBy((int) ((x - oldx) * 4), 0);

		}

	}
}
